package demo.swing.date;

import java.util.ArrayList;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.event.ListDataListener;

public class IntegerComboBoxModel implements ComboBoxModel<Integer> {

	private List<Integer> data = new ArrayList<Integer>();
	private int selected = 0;
	public IntegerComboBoxModel(Integer left, Integer right){
		for (int i = left; i <= right; i++){
			data.add(new Integer(i));
		}
	}
	@Override
	public int getSize() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Integer getElementAt(int index) {
		// TODO Auto-generated method stub
		return (Integer)data.get(index);
	}

	@Override
	public void addListDataListener(ListDataListener l) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void removeListDataListener(ListDataListener l) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setSelectedItem(Object anItem) {
		// TODO Auto-generated method stub
		for(int i = 0; i < data.size(); i++){
			if (data.get(i).equals(anItem)){
				selected = i;
				break;
			}
		}
		return;
	}

	@Override
	public Object getSelectedItem() {
		// TODO Auto-generated method stub
		return (Object)data.get(selected);
	}
	public int getIntSelectedItem(){
		return data.get(selected);
	}

}
